package com.smartens.boit.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.smartens.boit.MainActivity;
import com.smartens.boit.R;
import com.smartens.boit.activity.AbnormalActivity;
import com.smartens.boit.activity.NormalActivity;
import com.smartens.boit.activity.UnderlineActivity;

import static com.smartens.boit.R.id.lixiantext;

/**
 * @Description 设备管理
 * @Author songtt
 * @Date 2021/3/4
 */
public class FirstFragment extends Fragment implements View.OnClickListener {
    private LinearLayout normal;
    private LinearLayout unNormal;
    private LinearLayout underLine;
    private MainActivity mainActivity;

    public int getNormal_n() {
        return normal_n;
    }

    public void setNormal_n(int normal_n) {
        normal_n=Math.max(0,normal_n);
        this.normal_n = normal_n;
        if (normal_num!=null)
        normal_num.setText(normal_n+"");
    }

    public int getUnnormal_n() {
        return unnormal_n;
    }

    public void setUnnormal_n(int unnormal_n) {
        unnormal_n= Math.min(1,unnormal_n);
        this.unnormal_n = unnormal_n;
        if (unnormal_num!=null)
        unnormal_num.setText(unnormal_n+"");
    }
    private  int normal_n=1;
    private  int unnormal_n=0;
    private  int lixiannum;

    private TextView normal_num,unnormal_num,lixiantext;

    public int getLixiannum() {
        return lixiannum;
    }

    public void setLixiannum(int lixiannum) {
        this.lixiannum = lixiannum;
        if (lixiantext!=null)
        lixiantext.setText(lixiannum+"");
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mainActivity= (MainActivity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =  inflater.inflate(R.layout.fragment_first, container, false);
        lixiantext=view.findViewById(R.id.lixiantext);
        normal = view.findViewById(R.id.normal);
        unNormal = view.findViewById(R.id.unNormal);
        normal_num=view.findViewById(R.id.normalnum);
        unnormal_num=view.findViewById(R.id.unnormal_num);
        underLine = view.findViewById(R.id.underLine);
        initView();
        updataNum();
        return view;

    }

    private void updataNum() {
        normal_num.setText(normal_n+"");
        unnormal_num.setText(unnormal_n+"");
    }

    private void initView() {
        normal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(getActivity(), NormalActivity.class);
                startActivity(intent);
            }
        });
        unNormal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (unnormal_n==0)
                {
                    return;
                }
                Intent intent = new Intent(getActivity(),UnderlineActivity.class);
                startActivity(intent);
            }
        });
        underLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), AbnormalActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

   /*     if (((MainActivity)getActivity()).secondFragment!=null&& ((MainActivity)getActivity()).secondFragment.isErrorC())
        {

              setUnnormal_n(0);
              setNormal_n(1);

        }*/

    }
}